library(sf)
## Linking to GEOS 3.8.1, GDAL 3.1.4, PROJ 6.3.1
library(readxl)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(plyr)
## ------------------------------------------------------------------------------
## You have loaded plyr after dplyr - this is likely to cause problems.
## If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
## library(plyr); library(dplyr)
## ------------------------------------------------------------------------------
## 
## Attaching package: 'plyr'
## The following objects are masked from 'package:dplyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
library(ggplot2)
library(afrihealthsites)
library(ggpubr)
## 
## Attaching package: 'ggpubr'
## The following object is masked from 'package:plyr':
## 
##     mutate
library(afriadmin)
## 
## Attaching package: 'afriadmin'
## The following objects are masked from 'package:afrihealthsites':
## 
##     country2iso, iso2country
library(tmap)

# Install Malawi MFL
malawi_MFL = read_excel("~/malawi-health-facilities-1/MHFR_Facilities 1.xlsx")
head(malawi_MFL)
## # A tibble: 6 x 11
##   CODE  NAME  `COMMON NAME` OWNERSHIP TYPE  STATUS ZONE  DISTRICT `DATE OPENED`
##   <chr> <chr> <chr>         <chr>     <chr> <chr>  <chr> <chr>    <chr>        
## 1 MC01… A + … A+A           Private   Clin… Funct… Cent… Mchinji  Jan 1st 75   
## 2 BT24… A-C … A.C Opticals  Private   Clin… Funct… Sout… Blantyre Jan 1st 75   
## 3 MZ16… A-C … A-C Opticals  Mission/… Clin… Non-f… Nort… Mzimba   Jan 1st 75   
## 4 BT24… Akwe… Akwezeke Pvt  Private   Clin… Funct… Sout… Blantyre Jan 1st 75   
## 5 BT24… AB M… Abowa         Private   Clin… Funct… Sout… Blantyre Jan 1st 75   
## 6 LL04… ABC … ABC Clinic    Christia… Hosp… Funct… Cent… Lilongwe Jan 1st 75   
## # … with 2 more variables: LATITUDE <chr>, LONGITUDE <chr>
# Convert to sf

## omit NA's
new_malawi_MFL = na.omit(malawi_MFL)

## check for NA 
any(is.na(new_malawi_MFL))
## [1] FALSE
## transform geometry columns into numeric 
sapply(new_malawi_MFL, class)
##        CODE        NAME COMMON NAME   OWNERSHIP        TYPE      STATUS 
## "character" "character" "character" "character" "character" "character" 
##        ZONE    DISTRICT DATE OPENED    LATITUDE   LONGITUDE 
## "character" "character" "character" "character" "character"
new_malawi_MFL = transform(new_malawi_MFL, LATITUDE = as.numeric(LATITUDE), 
                                           LONGITUDE = as.numeric(LONGITUDE))
## Warning in eval(substitute(list(...)), `_data`, parent.frame()): NAs introduced
## by coercion
any(is.na(new_malawi_MFL)) ## check for NA
## [1] TRUE
new_malawi_MFL = na.omit(new_malawi_MFL) ## and omit

## convert to sf object
malawi_facilities_MFL = st_as_sf(new_malawi_MFL, coords = c("LONGITUDE", "LATITUDE"), dim = "XY")

malawi_facilities_MFL = st_set_crs(malawi_facilities_MFL, 4326) ## set CRS, is WGS84 right?

malawi_facilities_MFL
## Simple feature collection with 1426 features and 9 fields
## geometry type:  POINT
## dimension:      XY
## bbox:           xmin: 1 ymin: -542183 xmax: 70989710 ymax: -1
## geographic CRS: WGS 84
## First 10 features:
##        CODE                                               NAME
## 1  MC010002                               A + A private clinic
## 2  BT240003                                       A-C Opticals
## 3  BT240005                                Akwezeke PVT Clinic
## 4  BT240006                                  AB Medical Clinic
## 5  LL040007                                 ABC Comm. Hospital
## 6  LL040010 Achikondi Women Community Friendly Services Clinic
## 7  LL040011                        Lilongwe Adventist Hospital
## 8  LL040012                    Adventist Health Centre Area 15
## 9  LL040013                         Africa Leaf Clinic Kanengo
## 10 ZA230014                        MAIMED HEALTH CARE SERVICES
##                   COMMON.NAME                                     OWNERSHIP
## 1                         A+A                                       Private
## 2                A.C Opticals                                       Private
## 3                Akwezeke Pvt                                       Private
## 4                       Abowa                                       Private
## 5                  ABC Clinic Christian Health Association of Malawi (CHAM)
## 6                   Achikondi                                       Private
## 7     Adventist Health Centre Christian Health Association of Malawi (CHAM)
## 8                   Adventist Christian Health Association of Malawi (CHAM)
## 9  Africa Leaf Clinic Kanengo                                       Private
## 10                        AHI                                       Private
##             TYPE         STATUS               ZONE DISTRICT DATE.OPENED
## 1         Clinic     Functional Centrals West Zone  Mchinji  Jan 1st 75
## 2         Clinic     Functional    South East Zone Blantyre  Jan 1st 75
## 3         Clinic     Functional    South East Zone Blantyre  Jan 1st 75
## 4         Clinic     Functional    South East Zone Blantyre  Jan 1st 75
## 5       Hospital     Functional Centrals West Zone Lilongwe  Jan 1st 75
## 6     Dispensary     Functional Centrals West Zone Lilongwe  Jan 1st 75
## 7       Hospital     Functional Centrals West Zone Lilongwe  Jan 1st 83
## 8  Health Centre     Functional Centrals West Zone Lilongwe  Jan 1st 75
## 9         Clinic Non-functional Centrals West Zone Lilongwe  Jan 1st 75
## 10        Clinic     Functional    South West Zone    Zomba  Aug 1st 18
##                      geometry
## 1  POINT (33.88563 -13.79742)
## 2         POINT (35.03 -15.8)
## 3        POINT (35.09 -15.84)
## 4        POINT (35.09 -15.84)
## 5  POINT (33.74129 -13.96816)
## 6   POINT (33.7793 -13.95473)
## 7   POINT (33.7793 -13.95473)
## 8   POINT (33.7793 -13.95473)
## 9   POINT (33.80487 -13.8898)
## 10  POINT (35.3223 -15.38361)

Overview: 1. Malawi MFL - Facility locations managed by the Ministry of Health and Population Malawi. WHO guidance states that it should be updated at least every 2 years. Last update is unknown. - Locations in lat-long, CRS set to WGS84 - 1546 facilities reported, data includes name, ownership, type of facility and functional status.

# Number of each type
facility_types_MFL = as.data.frame(table(malawi_MFL$TYPE))
facility_types_MFL
##                Var1 Freq
## 1  Central Hospital    4
## 2            Clinic  585
## 3        Dispensary  179
## 4 District Hospital   24
## 5     Health Centre  520
## 6       Health Post  138
## 7          Hospital   89
## 8           Private    6
## 9      Unclassified    1
## bar plot of no. of facility types 
plot_facility_types_MFL = ggplot(facility_types_MFL, aes(x=Var1, y=Freq)) + geom_bar(stat = "identity")
plot_facility_types_MFL

# Number of each type of ownership
ownership_MFL = as.data.frame(table(malawi_MFL$OWNERSHIP))
ownership_MFL
##                                            Var1 Freq
## 1                               Aquaid Lifeline    1
## 2 Christian Health Association of Malawi (CHAM)  192
## 3                                    Government  695
## 4         Mission/Faith-based (other than CHAM)   62
## 5                                Non-Government   69
## 6                                         Other   27
## 7                                    Parastatal    5
## 8                                       Private  495
## bar plot of ownership
plot_ownership_MFL = ggplot(ownership_MFL, aes(x=Var1, y=Freq)) + geom_bar(stat = "identity")
plot_ownership_MFL

  1. WHO-KWTRP
    • Focuses on facilities run by government, faith-based organisations, NGO’s and local authorities. Covers 50 countries in sub-Saharan Africa. Sources of information include health sector reports, websites run by national or international organisations and personal communications

    • If MFL was available it was used. More than one datasource was often used to compile facility list

    • Private facilities are excluded, duplicates removed, name errors corrected and name variations were matched. Missing info was added with the use of other datasources.

    • Now hosted by the WHO Global Malaria Programme, last update February 2019

    • Malawi datasources includes MFL, https://data.humdata.org/dataset/malawi-health and http://www.cham.org.mw/uploads/7/3/0/8/73088105/cham_health_facilities_-_1_june_2016.pdf

    • At time of publishing, 639 facilities with 9 missing coordinates, not been updated since

    • Data includes facility name, type, ownership, source of location and reclassified facility types

# Malawi WHO data.frame
malawi_WHO <- afrihealthsites("malawi", datasource='who', plot=FALSE, returnclass='dataframe')

head(malawi_WHO)
## # A tibble: 6 x 10
##   Country Admin1 `Facility name` `Facility type` Ownership   Lat  Long
##   <chr>   <chr>  <chr>           <chr>           <chr>     <dbl> <dbl>
## 1 Malawi  Centr… 80 Block Clinic Clinic          MoH       -12.9  33.4
## 2 Malawi  Centr… ABC Community … Clinic          FBO       -14.0  33.7
## 3 Malawi  Centr… Adventist Heal… Health Centre   FBO       -14.0  33.8
## 4 Malawi  Centr… Alinafe Commun… Community Hosp… FBO       -13.4  34.2
## 5 Malawi  Centr… Area 18 Health… Health Centre   MoH       -13.9  33.8
## 6 Malawi  Centr… Area 25 Health… Health Centre   MoH       -13.9  33.8
## # … with 3 more variables: `LL source` <chr>, iso3c <chr>,
## #   facility_type_9 <chr>
# No. of original facility types 
facility_types_WHO = as.data.frame(table(malawi_WHO$`Facility type`))
facility_types_WHO
##                     Var1 Freq
## 1       Central Hospital    4
## 2                 Clinic   22
## 3     Community Hospital    2
## 4      District Hospital   24
## 5          Health Centre  457
## 6 Health Post/Dispensary   87
## 7       Mission Hospital   27
## 8         Rural Hospital   25
## bar plot of original facility types 
plot_facility_types_WHO = ggplot(facility_types_WHO, aes(x=Var1, y=Freq)) + geom_bar(stat = "identity")
plot_facility_types_WHO

# No. of reclassified facility types
RC_facility_types_WHO = as.data.frame(table(malawi_WHO$facility_type_9))
RC_facility_types_WHO
##                    Var1 Freq
## 1 Community Health Unit    2
## 2         Health Centre  457
## 3         Health Clinic   22
## 4           Health Post   87
## 5              Hospital   80
## bar plot of reclassified facility types 
plot_RC_facility_types_WHO = ggplot(RC_facility_types_WHO, aes(x=Var1, y=Freq)) + geom_bar(stat = "identity")
plot_RC_facility_types_WHO

# Types of ownership
ownership_WHO = as.data.frame(table(malawi_WHO$Ownership))
ownership_WHO
##              Var1 Freq
## 1             FBO  173
## 2 Local authority    5
## 3             MoH  467
## 4             NGO    3
## bar plot of ownership
plot_ownership_WHO = ggplot(ownership_WHO, aes(x=Var1, y=Freq)) + geom_bar(stat = "identity")
plot_ownership_WHO

Both data sources contain no information on services available, capacity or equipment. MFL does state whether facility is functional.

Classification of MFL facilities aligns more with the structure of the health care system in Malawi (community, primary, secondary, tertiary), it differentiates central hospitals from district and other hospitals. WHO has additional rural and mission hospitals, where do they fit in?

https://www.health.gov.mw/index.php/2016-01-06-19-58-23/national-aids states that at community level, health posts, dispensaries and maternity clinics offer services. Primary includes health centers and community hospitals, secondary consists of district and some CHAM hospitals, tertiary includes central hospitals.

Analysis:

# facility types
plot_facilities = ggarrange(plot_facility_types_MFL, plot_RC_facility_types_WHO, 
                           ncol = 2,
                           labels = c("A", "B"))
plot_facilities

# ownership
plot_ownership = ggarrange(plot_ownership_MFL, plot_ownership_WHO, 
                           ncol = 2, 
                           labels = c("A", "B"))
plot_ownership

- Maps

# choose admin level
malawi_admin <- afriadmin("malawi",level=2, plot='sf')

# static WHO facility location map
map_static_WHO = afrihealthsites("malawi", datasource='who', plot='sf')

# combined plot of MFL and WHO facilities, static 
plot(st_geometry(malawi_admin))
plot(st_geometry(map_static_WHO), add = TRUE)
plot(st_geometry(malawi_facilities_MFL), add = TRUE)

# tmap

tmap_mode("view")
## tmap mode set to interactive viewing
## admin map
tmap_admin = tm_shape(st_geometry(malawi_admin)) + tm_borders()

## MFL facility locations
tmap_facilities_MFL = tmap_admin + tm_shape(malawi_facilities_MFL) + tm_dots(col = "TYPE", palette = "viridis") + tm_layout(frame = FALSE, asp = 2, title = "MFL", title.position = c("left", "top"))
tmap_facilities_MFL
## Warning in sf::st_is_longlat(shp2): bounding box has potentially an invalid
## value range for longlat data
## WHO facility locations
tmap_facilities_WHO = tmap_admin + tm_shape(map_static_WHO) + tm_dots(col = "facility_type_9", palette = "viridis") + tm_layout(frame = FALSE, asp = 2, title = "WHO", title.position = c("left", "top"))
tmap_facilities_WHO
## combined 
tmap_facilities_MFL_WHO = tmap_facilities_WHO + tm_shape(malawi_facilities_MFL) + tm_bubbles(col = "TYPE", palette = "YlOrRd", size = 0.05, alpha = 0.7) + tm_layout(frame = FALSE, asp = 2, title = "MFL & WHO", title.position = c("left", "top"))
tmap_facilities_MFL_WHO
## Warning in sf::st_is_longlat(shp2): bounding box has potentially an invalid
## value range for longlat data
## final 
tmap_arrange(tmap_facilities_MFL, tmap_facilities_WHO, ncol = 2) # side by side
## Warning in sf::st_is_longlat(shp2): bounding box has potentially an invalid
## value range for longlat data
tmap_facilities_MFL_WHO = tmap_facilities_WHO + tm_shape(malawi_facilities_MFL) + tm_dots(col = "TYPE", palette = "YlOrRd", alpha = 0.7) + tm_layout(frame = FALSE, asp = 2, title = "MFL & WHO", title.position = c("left", "top")) 
tmap_facilities_MFL_WHO # combined
## Warning in sf::st_is_longlat(shp2): bounding box has potentially an invalid
## value range for longlat data

Qs to address?:

  1. How many facilities are in the same location across the MFL and WHO datasets?
  2. Do same facilities share same names/other attributes?
  3. The ones that aren’t, are they within 50m of another facility?
# Qs 1 - how many intersect?

## convert malawi_WHO to sf object

class(malawi_WHO)
## [1] "tbl_df"     "tbl"        "data.frame"
any(is.na(malawi_WHO))
## [1] TRUE
new_malawi_WHO = na.omit(malawi_WHO) ## omit NA

sf_malawi_WHO = st_as_sf(new_malawi_WHO, coords = c("Long", "Lat"), dim = "XY")
sf_malawi_WHO = st_set_crs(sf_malawi_WHO, 4326)

## st_intersection
intersect_WHO_MFL = st_intersection(x=sf_malawi_WHO, y=malawi_facilities_MFL)
## although coordinates are longitude/latitude, st_intersection assumes that they are planar
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
intersect_WHO_MFL ## only 2 intersect directly, so are same up to 5 decimal places?
## Simple feature collection with 2 features and 17 fields
## geometry type:  POINT
## dimension:      XY
## bbox:           xmin: 33.29456 ymin: -11.53894 xmax: 33.41925 ymax: -11.45836
## geographic CRS: WGS 84
## # A tibble: 2 x 18
##   Country Admin1 Facility.name Facility.type Ownership LL.source iso3c
## * <chr>   <chr>  <chr>         <chr>         <chr>     <chr>     <chr>
## 1 Malawi  North… Euthini Heal… Health Centre MoH       GPS       MWI  
## 2 Malawi  North… Madede Healt… Health Centre MoH       GPS       MWI  
## # … with 11 more variables: facility_type_9 <chr>, CODE <chr>, NAME <chr>,
## #   COMMON.NAME <chr>, OWNERSHIP <chr>, TYPE <chr>, STATUS <chr>, ZONE <chr>,
## #   DISTRICT <chr>, DATE.OPENED <chr>, geometry <POINT [°]>
# Qs 2 - Do they share same attributes
## ownership is same, 1 name is same, Euthini registered as a hospital in MFL but as a health centre in WHO

# Qs 3 - how many/which are within 50m of another facility?